<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: table_mobile_setting.php 31281 2012-08-03 02:29:27Z zhangjie $
     */

    if (!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }

    class table_cloud_message_status extends discuz_table {

        public function __construct() {
            $this->_table = 'cloud_message_status';
            $this->_pk = 'id';

            parent::__construct();
        }

        //插入数据库
        public function insert($arr) {
            return DB::insert($this->_table, $arr, true);
        }

        //更新数据库
        public function update($caid, $data) {
            $caid = intval($caid);
            if (!$data) {
                return;
            }
            //print_r($data);exit;
            return DB::update($this->_table, $data, DB::field($this->_pk, $caid));
        }

        //查找某条记录
        public function fetch_app_info($caid) {
            $caid = intval($caid);
            return DB::fetch_first("SELECT * FROM %t WHERE caid=%d", array($this->_table, $caid));
        }

        //查询所有limt数据
        public function fetch_all_limit($start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .
                ' ORDER BY ' . DB::order('disabled', 'desc') . ',' . DB::order('lasttime', 'desc') .
                DB::limit($start, $limit));
        }

        //查询所有limt数据
        public function fetch_all_not_limit() {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .  ' ORDER BY ' . DB::order('disabled', 'desc') . ',' . DB::order('lasttime', 'desc'));
        }

        //根据应用名称查询
        public function fetch_first_by_name($name) {
            return DB::fetch_first('SELECT * FROM ' . DB::table($this->_table) . ' where ' . DB::field('name', $name));
        }

        //查询应用名称排除要修改的应用名
        public function fetch_name_not_id($id, $name) {
            $id = intval($id);
            return DB::fetch_first('SELECT * FROM ' . DB::table($this->_table) . ' where ' . DB::field('name', $name) . ' and ' . DB::field('caid', $id, '<>'));
        }

        //通过名称查询应用list
        public function fetch_all_by_name($name) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .
                ' where ' . DB::field('name', '%' . $name . '%', 'like') .
                ' ORDER BY ' . DB::order('disabled', 'desc') . ',' . DB::order('lasttime', 'desc'));
        }
           //查询当天发送短信的次数
        public function fetch_user_send_message_count($caid,$mobile) {
            return DB::fetch_first('SELECT count(id) as count FROM ' . DB::table($this->_table) . ' where caid='.$caid.' and  mobile = '.$mobile.' and TO_DAYS(lasttime) = TO_DAYS(NOW())');
        }


    }